home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / OpenDoc 1.2b2c1 / Implementation / UI / WinStat.cpp < prev    next >
Encoding:
Text File  |  1997-02-13  |  57.1 KB  |  2,133 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        WinStat.cpp
  3.  
  4.     Contains:    Definition of ODWindowState class
  5.  
  6.     Owned by:    Chris Linn
  7.  
  8.     Copyright:    © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <9>      11/27/96    CSL        1385215: Changes for container app support
  13.          <8>      11/12/96    TJ        The new API no-longer uses STRICT_WINDOWS.
  14.          <7>     10/4/96    CSL        1389237: Don't shuffle window in AddWindow
  15.                                     if it is already visible
  16.          <6>     9/24/96    eeh        1315228: Verify part wrapper passed
  17.          <5>     9/18/96    CSL        1359431: Warn if root part does not create
  18.                                     a root window.
  19.          <4>     7/31/96    CSL        1373366: Problem with hidden floating
  20.                                     windows
  21.          <3>     6/21/96    CSL        1315410: Windows won't select properly.
  22.                                     1331320: New windows shown hilited when
  23.                                     opened with process in background.
  24.          <2>     1/15/96    TJ        Cleaned Up
  25.         <82>     11/2/95    RR        #1298525, 1298642 Internalize now uses a
  26.                                     SUView on the draftsProperties, and checks
  27.                                     for reference validity
  28.         <81>    10/26/95    eeh        1296308: deal with non-persistant frames in
  29.                                     Internalize
  30.         <80>    10/24/95    RR        #1295596 OpenWindows no longer calls
  31.                                     select() during normal document open.
  32.         <79>    10/18/95    RR        1289153: Recover from exceptions creating /
  33.                                                                         internalizing / registering
  34.                                     windows. Added TRY/CATCH in CATCH block of
  35.                                     ::INnternalize
  36.         <78>    10/17/95    jpa        1289153: Recover from exceptions creating /
  37.                                     internalizing / registering windows.
  38.         <77>    10/16/95    RR        #1293067 Pass shouldDispose to
  39.                                     RegisterWindow
  40.         <76>     10/8/95    TJ        Fixes Recomended by Refball
  41.         <75>     10/3/95    eeh        1287095: use ReleaseObject in
  42.                                     RegisterWindow
  43.         <74>     10/3/95    TJ        Changes done by RefBall Team
  44.         <73>     9/21/95    RR        # 1285189 AcquireFrontWindow calls
  45.                                     FrontWindow() rather than
  46.                                     GetFrontNonFloatingWindow
  47.         <72>     9/13/95    TÇ        1282067 FB3:  UI temp var before SOM_TRY
  48.         <71>     9/12/95    RR        #1274439 Don't activate/deactivate windows
  49.                                     when in background
  50.         <70>      9/6/95    RR        #(1236387) Deactivate before suspend.
  51.                                     Reactivate after Resume
  52.         <69>      9/1/95    RR        # 1279100/1280338 Added IsActive test to
  53.                                     SelectODWindow
  54.         <68>     8/26/95    TÇ        1274606 FB2: Patching Remarks
  55.         <67>     8/25/95    JBS        1263078 FB: fix part editor swapping
  56.         <66>     8/15/95    RR        # 1233767 Use window iterator in
  57.                                     SuspendResume
  58.         <65>     8/12/95    TÇ        1276812 Need to use TempObjs and TempRefs
  59.                                     for exception safety and to avoid TRY
  60.                                     blocks, 1276807 Opt./Bug: use StdTypIO
  61.                                     routines for portable streaming & smaller
  62.                                     footprint, 1276806 Optimization: use
  63.                                     kODFalse instead of kODTrue in comparisons
  64.         <64>      8/3/95    RR        #1257260: Collapse B classes. Remove
  65.                                     somInit methods. Don't call IsInitialized
  66.                                     or SubclassResponsibility
  67.         <63>      8/2/95    VL        1270320: Correct refcounting in
  68.                                     SetCurrentMenuBar and SetBaseMenuBar.
  69.         <62>     6/30/95    RR        1242642 BB Ref counting fixes in
  70.                                     HideODWindow.
  71.         <61>     6/28/95    RR        1242642 BB Mostly ref counting. AddWindow
  72.                                     and RemoveWindow adjust ref counts. Window
  73.                                     iterator skips items marked for lazy
  74.                                     deletion.
  75.         <60>     6/26/95    TÇ        1242642 BB:Fix refcounting bugs
  76.         <59>     6/25/95    TÇ        1242642 BB: Turn on ODDebug warning if
  77.                                     refcount is wrong in
  78.                                     ODRefCntObjectsomUninit.
  79.         <58>     6/22/95    RR        #1245283 Undoable frame deletion
  80.                                     #1209427 Changed private api between
  81.                                     iterator and iteratee. Allow deletion while
  82.                                     iterating
  83.         <57>     6/19/95    jpa        Added hook to check for path pop-up
  84.                                     (cmd-click title bar) [1259398]
  85.         <56>     6/15/95    RR        #1256879 Get->AcquireCurrentMenuBar
  86.         <55>      6/8/95    RR        #1257260 Collapse base classes. #1214898
  87.                                     StdTypes.r -> ODTypes.r
  88.         <54>     5/31/95    RR        #1251403 Release after AcquirePart #1251980
  89.                                     Missing release in GetFrontRootWindow
  90.         <53>     5/26/95    RR        #1251403: Multithreading naming support
  91.         <52>     5/25/95    jpa        List.h --> LinkList.h [1253324]
  92.         <51>     5/17/95    RR        #1250135/1250137/1250143 Getters increment
  93.                                     refcount
  94.         <50>     5/10/95    RR        # 1234319. Check for rootFrameList before
  95.                                     internalizing
  96.         <49>      5/4/95    eeh        1242889: get drafts string from resource
  97.         <48>      5/2/95    RR        # 1244133 Fixed SetDefaultWindowTitles to
  98.                                     avoid extra bogus characters
  99.         <47>     4/28/95    RR        1211085 Remove 5$ comments
  100.         <46>     4/14/95    TÇ        With RR & CG: #1194507 DR/BB:title bar of a
  101.                                     draft window doesn't reveal it is a draft
  102.                                     or which draft it is
  103.         <45>     4/13/95    RR        #1216618 Added ODVolatile
  104.         <44>      4/7/95    RR        #1216618 Added SOM_TRY etc.
  105.         <43>      4/6/95    RR        # 1236361 Call Deactivate in HideODWindow.
  106.                                     Remove redundant code to prevent
  107.                                     deadstripping of PlatformFile
  108.         <42>      4/4/95    RR        # 1220104 Use ODObjectsAreEqual
  109.         <41>     3/22/95    RR        #1225420, 1227993 Parts internalize
  110.                                     windows. Modified OpenWindow, Externalize,
  111.                                     Internalize. Added RegisterWindowForFrame
  112.         <40>     3/10/95    RR        # 1225861 Send Suspend/resume to invisible
  113.                                     windows
  114.         <39>      3/7/95    RR        # 1151165 Cleaned up AdjustPartMenus #
  115.                                     1220929 Added fMenuFocus
  116.         <38>      3/3/95    CC        # 1205622: Ensure activate event is
  117.                                     delivered after modal dialog is dismissed.
  118.         <37>      3/1/95    RR        # 1205622 ::OpenWindows now supports
  119.                                     re-opening an open draft by bringing its
  120.                                     windows to the front.
  121.         <36>     2/24/95    jpa        Use ODNewRgn. [1220810]
  122.         <35>     2/22/95    RR        # 1213850 Call AdjustMenus for root part of
  123.                                     active window before calling it for menu
  124.                                     focus
  125.         <34>     2/20/95    TÇ        #1221861 BB: Incomplete AOCE support needs
  126.                                     to be removed from OpenDoc
  127.         <33>     1/31/95    RR        # 1209165 Rewrote HandleAOCEEvent. #1209552
  128.                                     Call SendBehind in HideODWindow
  129.         <31>     1/26/95    VL        #???: Use updated Storage Unit Ref API.
  130.         <30>     1/25/95    RR        #1211853 Removed session parameter from
  131.                                     CreateMenuBar. Pass _fSession to
  132.                                     InitMenuBar
  133.         <29>     1/23/95    RR        # 1211853 Added CreateMenuBar
  134.         <28>      1/4/95    eeh        1209165: added test to
  135.                                     HandleAOCEMailerEvent
  136.         <27>    12/20/94    VL        1195012: Make Storage calls be
  137.                                     marshallable.
  138.         <26>    12/19/94    eeh        1192626: change ::Internalize not to
  139.                                     duplicate windows already open
  140.         <25>    11/28/94    RR        Check for AOCE presence
  141.         <24>     11/1/94    RR        #1196761 Don't exit HandleAOCEMailerEvent
  142.                                     without handling updates in inactive mailer
  143.                                     windows
  144.         <23>    10/18/94    RR        Used AcquireWindow(id) to validate windows in
  145.                                     CLoseWindows, in case part closed
  146.                                     subsidiary windows
  147.         <22>     9/29/94    RA        1189812: Mods for 68K build.
  148.         <21>     9/23/94    VL        1155579, 1184272: Use StorUtil to
  149.                                     create/get container and its file.
  150.         <20>     9/22/94    eeh        #1154961 AddAOCEMailer takes additional
  151.                                     param.
  152.         <19>     9/19/94    eeh        #1164891: check for userCanceledErr after
  153.                                     SMPMailerEvent call.
  154.         <18>      9/1/94    RR        #1176805 Release old base menu bar
  155.         <17>      9/1/94    CC        RADAR #1181971 - missing factory methods
  156.                                     (for JBS)
  157.         <16>     8/29/94    RR        #1171772 DOn't call SelectWindow
  158.         <15>     8/26/94    TÇ        #1181761 rename obsolete kOD IDs to correct
  159.                                     kODStrong/WeakStorageUnitRefs
  160.         <14>     8/26/94    VL        1183174: Use updated cloning APIs.
  161.         <13>     8/25/94    RR        Added private AcquireBaseMenuBar. Set
  162.                                     generation of menubar in SetBaseMenuBar
  163.         <12>     8/19/94    TÇ        #1180922 Need to Stop using obsolete types
  164.                                     (kOD ID)
  165.         <11>     8/18/94    jpa        Filled in CreateCanvas [1180387]
  166.         <10>     8/16/94    JBS        1180387: add CreateCanvas()
  167.          <9>     8/15/94    JBS        1181138: add frameType to CreateFrame();
  168.                                     1181156: UI API Cleanup
  169.          <8>      8/3/94    VL        1153123: Storage to ODStor.
  170.          <7>     7/27/94    eeh        fix use of Point and Rect (honesty to SOM…)
  171.          <6>     7/21/94    eeh        fix FixUpMailerWindow
  172.          <5>     7/15/94    TÇ        make sure PlatformFile code is not
  173.                                     deadstripped
  174.          <4>      7/8/94    RR        Converted HandleAOCEMailerEvent
  175.          <3>     6/27/94    eeh        add Environment* parameters to
  176.                                     AOCEHelperObj method calls
  177.          <2>     9/27/94    RR        Call InitBaseWindowState
  178.          <1>     9/26/94    RR        first checked in
  179.  
  180.     To Do:
  181.     In Progress:
  182.         
  183. */
  184.  
  185.  
  186. #define ODWindowState_Class_Source
  187. #define VARIABLE_MACROS
  188. #include <WinStat.xih>
  189.  
  190. #ifndef SOM_ODWindowIterator_xh
  191. #include <WinIter.xh>
  192. #endif
  193.  
  194. #ifndef _WINUTILM_
  195. #include "WinUtilM.h" 
  196. #endif
  197.  
  198. #ifndef _UIDEFS_
  199. #include "UIDefs.h"
  200. #endif
  201.  
  202. #ifndef _TEMPOBJ_
  203. #include <TempObj.h>
  204. #endif
  205.  
  206. #ifndef _STDTYPIO_
  207. #include <StdTypIO.h>
  208. #endif
  209.  
  210. #ifndef SOM_ODSession_xh
  211. #include <ODSessn.xh>
  212. #endif
  213.  
  214. #ifndef SOM_ODWindow_xh
  215. #include <Window.xh>
  216. #endif
  217.  
  218. #ifndef SOM_ODMenuBar_xh
  219. #include <MenuBar.xh>
  220. #endif
  221.  
  222. #ifndef SOM_ODArbitrator_xh
  223. #include <Arbitrat.xh>
  224. #endif
  225.  
  226. #ifndef SOM_Module_Apple_defined
  227. #include <Part.xh>
  228. #endif
  229.  
  230. #ifndef SOM_ODFrame_xh
  231. #include <Frame.xh>
  232. #endif
  233.  
  234. #ifndef SOM_ODFacet_xh
  235. #include <Facet.xh>
  236. #endif
  237.  
  238. #ifndef SOM_ODCanvas_xh
  239. #include <Canvas.xh>
  240. #endif
  241.  
  242. #ifndef SOM_ODDraft_xh
  243. #include <Draft.xh>
  244. #endif
  245.  
  246. #ifndef SOM_ODDocument_xh
  247. #include <Document.xh>
  248. #endif
  249.  
  250. #ifndef SOM_ODContainer_xh
  251. #include <ODCtr.xh>
  252. #endif
  253.  
  254. #ifndef SOM_ODStorageSystem_xh
  255. #include <ODStor.xh>
  256. #endif
  257.  
  258. #ifndef SOM_ODStorageUnit_xh
  259. #include <StorageU.xh>
  260. #endif
  261.  
  262. #ifndef SOM_Module_OpenDoc_Commands_defined
  263. #include <CmdDefs.xh>
  264. #endif
  265.  
  266. #ifndef __GESTALTEQU__
  267. #include <GestaltEqu.h>
  268. #endif
  269.  
  270. #ifndef _DLOGUTIL_
  271. #include <DlogUtil.h>
  272. #endif
  273.  
  274. #ifndef _DOCUTILS_
  275. #include <DocUtils.h>
  276. #endif
  277.  
  278. #ifndef _USERSRCM_
  279. #include <UseRsrcM.h>
  280. #endif
  281.  
  282. #ifndef _PLFMFILE_
  283. #include <PlfmFile.h>
  284. #endif
  285.  
  286. #ifndef _PASCLSTR_
  287. #include "PasclStr.h"
  288. #endif
  289.  
  290. #ifndef _LINKLIST_
  291. #include <LinkList.h>
  292. #endif
  293.  
  294. #ifndef _ORDCOLL_
  295. #include "OrdColl.h"
  296. #endif
  297.  
  298. #ifndef _EXCEPT_
  299. #include "Except.h"
  300. #endif
  301.  
  302. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  303. #include <StdTypes.xh>
  304. #endif
  305.  
  306. #ifndef SOM_Module_OpenDoc_StdProps_defined
  307. #include <StdProps.xh>
  308. #endif
  309.  
  310. #ifndef SOM_Module_OpenDoc_Foci_defined
  311. #include <Foci.xh>
  312. #endif
  313.  
  314. #ifndef _ODUTILS_
  315. #include <ODUtils.h>
  316. #endif
  317.  
  318. #ifndef _STORUTIL
  319. #include <StorUtil.h>
  320. #endif
  321.  
  322. #ifndef __LOWMEM__
  323. #include <LowMem.h> // For WindowList global
  324. #endif
  325.  
  326. #ifndef __TOOLUTILS__
  327. #include <ToolUtils.h>
  328. #endif
  329.  
  330. #ifndef _ODDEBUG_
  331. #include "ODDebug.h"    // Adkins -- added
  332. #endif
  333.  
  334. #ifndef _WINPOPM_
  335. #include "WinPopM.h"
  336. #endif
  337.  
  338. #ifndef SOM_ODStandardWindowLayerModule_xh
  339. #include "StdWMod.xh"
  340. #endif
  341.  
  342. #ifndef SOM_ODDispatcher_xh
  343. #include <Disptch.xh>
  344. #endif
  345.  
  346. #ifndef _DSPUTILM_
  347. #include "DspUtilM.h" 
  348. #endif
  349.  
  350. #define ODDebugActivates 0
  351.  
  352. #pragma segment ODWindowState
  353.  
  354. #include "WinStatB.cpp"    // Platform-independent methods, if any
  355.  
  356. SOM_Scope void  SOMLINK ODWindowStateDeactivateFrontWindows(ODWindowState *somSelf, Environment *ev)
  357. {
  358.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  359.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateDeactivateFrontWindows");
  360.     
  361.     _fWindowModule->DeactivateFrontWindows( ev );
  362. }
  363.  
  364. SOM_Scope void  SOMLINK ODWindowStateActivateFrontWindows(ODWindowState *somSelf, Environment *ev)
  365. {
  366.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  367.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateActivateFrontWindows");
  368.  
  369.     _fWindowModule->ActivateFrontWindows( ev );
  370. }
  371.  
  372. SOM_Scope ODWindow*  SOMLINK ODWindowStateAcquireFrontWindow(ODWindowState *somSelf, Environment *ev)
  373. {
  374.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  375.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateAcquireFrontWindow");
  376.  
  377.     ODWindow*    odWindow = kODNULL;
  378.  
  379.     SOM_TRY
  380.  
  381.         WindowPtr window = ::FrontWindow();
  382.         
  383.         if (window != kODNULL) 
  384.         {
  385.             if (somSelf->IsODWindow(ev,window))
  386.                 odWindow = somSelf->AcquireODWindow(ev,window);
  387.         }
  388.  
  389.     SOM_CATCH_ALL
  390.     SOM_ENDTRY
  391.         
  392.     return odWindow;
  393. }
  394.  
  395. SOM_Scope ODWindow*  SOMLINK ODWindowStateAcquireFrontFloatingWindow(ODWindowState *somSelf, Environment *ev)
  396. {
  397.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  398.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateAcquireFrontFloatingWindow");
  399.  
  400.     ODWindow* frontFloatingWindow = kODNULL;
  401.     
  402.     SOM_TRY
  403.     
  404.         WindowListIterator    iter;
  405.         
  406.         WindowPtr    platformWindow = iter.First();
  407.         while (iter.IsNotComplete() && (frontFloatingWindow == kODNULL)) 
  408.         {
  409.             ODWindow*    odWindow = somSelf->AcquireODWindow(ev,platformWindow);
  410.             if (odWindow != kODNULL) 
  411.             {
  412.                 if ( odWindow->IsFloating( ev ) && odWindow->IsShown( ev )) 
  413.                     frontFloatingWindow = odWindow;
  414.                 else
  415.                     ODReleaseObject(ev, odWindow);    // TÇ: released only if we don't want it.
  416.             }
  417.         }
  418.  
  419.     SOM_CATCH_ALL
  420.  
  421.         ODSafeReleaseObject( frontFloatingWindow );
  422.         frontFloatingWindow = kODNULL;
  423.         
  424.     SOM_ENDTRY
  425.  
  426.     return frontFloatingWindow;
  427. }
  428.  
  429. SOM_Scope ODWindow*  SOMLINK ODWindowStateAcquireFrontRootWindow(ODWindowState *somSelf, Environment *ev)
  430. {
  431.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  432.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateAcquireFrontRootWindow");
  433.  
  434.     ODWindow* odWindow = kODNULL;
  435.  
  436.     SOM_TRY
  437.  
  438.         WindowListIterator    iter;
  439.         
  440.         for (WindowPtr platformWindow = iter.First(); 
  441.             iter.IsNotComplete(); 
  442.             platformWindow = iter.Next())
  443.         {
  444.             odWindow = somSelf->AcquireODWindow(ev,platformWindow);
  445.             if (    odWindow != kODNULL
  446.                  && odWindow->IsShown( ev )
  447.                  && odWindow->IsRootWindow( ev ))
  448.                 break;
  449.             else
  450.                 ODReleaseObject(ev, odWindow);                
  451.         }
  452.  
  453.     SOM_CATCH_ALL
  454.  
  455.         ODSafeReleaseObject( odWindow );
  456.         odWindow = kODNULL;
  457.         
  458.     SOM_ENDTRY
  459.  
  460.     return odWindow;    // -- TÇ: was acquired in the for loop above.
  461. }
  462.  
  463. SOM_Scope void  SOMLINK ODWindowStateInitWindowState(ODWindowState *somSelf, Environment *ev,
  464.         ODSession* session)
  465. {
  466.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  467.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateInitWindowState");
  468.  
  469.     LinkedList* linkedList = kODNULL; ODVolatile(linkedList);
  470.     
  471.     SOM_TRY
  472.     
  473.         /* Moved from somInit. SOM itself sets fields to zero
  474.         _fWindowList = kODNULL;
  475.         _fSession = kODNULL;
  476.         _fBaseMenuBar = kODNULL;
  477.         _fCurrentMenuBar = kODNULL;
  478.         _fNextID = 0;
  479.         _fMenuFocus = 0;
  480.         _fIteratorCount = 0;
  481.         _fWindowModule = kODNULL;
  482.         _fWindowModuleHasBeenSet = 0;
  483.         */
  484.         
  485.         somSelf->InitObject(ev);    
  486.         _fSession = session;
  487.         _fMenuFocus = _fSession->Tokenize(ev,kODMenuFocus);
  488.         linkedList = new LinkedList;
  489.         _fWindowList = linkedList;
  490.         
  491.         ODStandardWindowModule* stdWindowModule = new ODStandardWindowModule;
  492.         THROW_IF_NULL( stdWindowModule );
  493.         stdWindowModule->InitStandardWindowModule( ev, somSelf );
  494.         stdWindowModule->Acquire( ev );
  495.         _fWindowModule = stdWindowModule;
  496.         _fWindowModuleHasBeenSet = kODFalse;
  497.  
  498.     SOM_CATCH_ALL
  499.     
  500.         ODDeleteObject(linkedList);
  501.  
  502.     SOM_ENDTRY
  503. }
  504.  
  505. SOM_Scope void  SOMLINK ODWindowStateSetCurrentMenuBar(ODWindowState *somSelf, Environment *ev,
  506.         ODMenuBar* theMenuBar)
  507. {
  508.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  509.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateSetCurrentMenuBar");
  510.  
  511.     SOM_TRY
  512.  
  513.         if (!ODObjectsAreEqual(ev, _fCurrentMenuBar, theMenuBar))
  514.         {
  515.             ODReleaseObject(ev, _fCurrentMenuBar);
  516.             if (theMenuBar)
  517.                 theMenuBar->Acquire(ev);
  518.             _fCurrentMenuBar = theMenuBar;
  519.         }
  520.  
  521.     SOM_CATCH_ALL
  522.     SOM_ENDTRY
  523. }
  524.  
  525. SOM_Scope ODMenuBar*  SOMLINK ODWindowStateAcquireCurrentMenuBar(ODWindowState *somSelf, Environment *ev)
  526. {
  527.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  528.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateGetCurrentMenuBar");
  529.  
  530.     SOM_TRY
  531.     
  532.     if (_fCurrentMenuBar)
  533.         _fCurrentMenuBar->Acquire(ev);
  534.     
  535.     SOM_CATCH_ALL
  536.     SOM_ENDTRY
  537.     return _fCurrentMenuBar;
  538. }
  539.  
  540. SOM_Scope ODMenuBar*  SOMLINK ODWindowStateAcquireBaseMenuBar(ODWindowState *somSelf, Environment *ev)
  541. {
  542.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  543.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateAcquireBaseMenuBar");
  544.  
  545.     SOM_TRY
  546.     
  547.     if (_fBaseMenuBar)
  548.         _fBaseMenuBar->Acquire(ev);
  549.     
  550.     SOM_CATCH_ALL
  551.     SOM_ENDTRY
  552.     
  553.     return _fBaseMenuBar;
  554. }
  555.  
  556. SOM_Scope ODWindow*  SOMLINK ODWindowStateAddWindow(ODWindowState *somSelf, Environment *ev,
  557.         ODWindow* window)
  558. {
  559.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  560.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateAddWindow");
  561.  
  562.     SOM_TRY
  563.  
  564.         if (window)
  565.         {
  566.             ODBoolean found = kODFalse;
  567.             WindowLink* foundLink = kODNULL;
  568.         
  569.             LinkedListIterator iter(_fWindowList);
  570.             
  571.             for ( WindowLink* link = (WindowLink*) iter.First();
  572.                     iter.IsNotComplete(); 
  573.                     link = (WindowLink*) iter.Next())
  574.             {
  575.                 if (!link->ShouldRemove() && ODObjectsAreEqual(ev, link->fWindow, window))
  576.                 {
  577.                     found = kODTrue;
  578.                     foundLink = link;
  579.                     break;                
  580.                 }
  581.             }
  582.             if (!found)
  583.             {
  584.                 window->Acquire(ev);
  585.                 WindowLink* link = kODNULL;            ODVolatile( link );
  586.                 TRY
  587.                     _fNextID++;
  588.                     link = new WindowLink(_fNextID, window);
  589.                     window->SetID(ev,_fNextID);
  590.                     THROW_IF_NULL(link);
  591.                     _fWindowList->AddLast(link);
  592.                     
  593.                     if ( window->IsShown( ev ))
  594.                         _fWindowModule->ShowWindow( ev, window->GetPlatformWindow( ev ),
  595.                                 window->IsFloating( ev ) ? kODWinLayerFloating
  596.                                                          : kODWinLayerDocument );
  597.                 CATCH_ALL
  598.                     if ( link )
  599.                     {
  600.                         if ( _fIteratorCount > 0 )
  601.                         {
  602.                             link->fRemove = kODTrue;
  603.                         }
  604.                         else
  605.                         {
  606.                             _fWindowList->Remove( *link );
  607.                             ODDeleteObject( link );
  608.                         }
  609.                     }
  610.                     ODSafeReleaseObject( window );
  611.                     RERAISE;
  612.                 ENDTRY
  613.             }
  614.         }
  615.  
  616.     SOM_CATCH_ALL
  617.     
  618.         window = kODNULL;
  619.         
  620.     SOM_ENDTRY
  621.  
  622.     return window;
  623. }
  624.  
  625. SOM_Scope void  SOMLINK ODWindowStateRemoveWindow(ODWindowState *somSelf, Environment *ev,
  626.         ODWindow* oldWindow)
  627. {
  628.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  629.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateRemoveWindow");
  630.  
  631.     SOM_TRY
  632.     
  633.         ODBoolean found = kODFalse;
  634.         WindowLink* foundLink = kODNULL;
  635.     
  636.         LinkedListIterator iter(_fWindowList);
  637.         
  638.         for ( WindowLink* link = (WindowLink*) iter.First();
  639.                 iter.IsNotComplete(); 
  640.                 link = (WindowLink*) iter.Next())
  641.         {
  642.             if (!link->ShouldRemove() && ODObjectsAreEqual(ev, link->fWindow, oldWindow))
  643.             {
  644.                 found = kODTrue;
  645.                 foundLink = link;
  646.                 break;                
  647.             }
  648.         }
  649.         if (found)
  650.         {
  651.             ODWindow* window = foundLink->fWindow;
  652.  
  653.             if ( window->IsShown( ev ))
  654.                 _fWindowModule->HideWindow( ev, window->GetPlatformWindow( ev ));
  655.  
  656.             ODReleaseObject(ev, window);
  657.             if (_fIteratorCount > 0)
  658.             {
  659.                 foundLink->fRemove = kODTrue;
  660.             }
  661.             else
  662.             {
  663.                 _fWindowList->Remove(*foundLink);
  664.                 ODDeleteObject(foundLink);
  665.             }
  666.         }
  667.         
  668.     SOM_CATCH_ALL
  669.     SOM_ENDTRY
  670. }
  671.  
  672. SOM_Scope ODWindow*  SOMLINK ODWindowStateFindODWindow(ODWindowState *somSelf, Environment *ev,
  673.         Point* globalPoint)
  674. {
  675.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  676.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateFindODWindow");
  677.  
  678.     ODWindow* odWindow = kODNULL;
  679.     
  680.     SOM_TRY
  681.     
  682.         WindowPtr window;
  683.         FindWindow(*globalPoint, &window);
  684.         if (window)
  685.             odWindow = somSelf->AcquireODWindow(ev,window);
  686.  
  687.     SOM_CATCH_ALL
  688.     SOM_ENDTRY
  689.     
  690.     return odWindow;    // -- TÇ: ODWindowStateFindODWindow is an 'acquire' function
  691. }
  692.  
  693. SOM_Scope void  SOMLINK ODWindowStateReleaseWindow(ODWindowState *somSelf, Environment *ev,
  694.         ODWindow* window)
  695. {
  696.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  697.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateReleaseWindow");
  698.  
  699.     SOM_TRY
  700.  
  701.         ODDeleteObject(window);
  702.  
  703.     SOM_CATCH_ALL
  704.     SOM_ENDTRY
  705. }
  706.  
  707. SOM_Scope void  SOMLINK ODWindowStateSuspendResume(ODWindowState *somSelf, Environment *ev,
  708.         ODEventData* event)
  709. {
  710.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  711.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateSuspendResume");
  712.  
  713.     SOM_TRY
  714.     
  715.         const short kResumeMask = 0x01;    // High byte suspend/resume event 
  716.         
  717.         ODBoolean    goingToBackground = (event->message & kResumeMask) == 0;
  718.  
  719.     #if ODDebug && ODDebugActivates
  720.         somPrintf("WindowState Suspend/Resume %d\n", !goingToBackground);
  721.     #endif
  722.  
  723.         // Suspend/Resume each window
  724.         ODWindowIterator* iter = somSelf->CreateWindowIterator(ev);        
  725.         for (ODWindow* window = iter->First(ev); iter->IsNotComplete(ev); window = iter->Next(ev))
  726.         {
  727.             window->SuspendResume(ev,event);
  728.         }
  729.         ODDeleteObject(iter);
  730.  
  731.         // Draw or invalidate the active frame boarder
  732.         ODTypeToken selectionFocus = _fSession->Tokenize( ev, kODSelectionFocus );
  733.         TempODFrame activeFrame = _fSession->GetArbitrator(ev)->AcquireFocusOwner( ev, selectionFocus );
  734.         if ( activeFrame != kODNULL )
  735.         {
  736.             if ( goingToBackground )
  737.                 activeFrame->InvalidateActiveBorder( ev );
  738.             else    // Limitation of API: Can't call Invalidate twice, because shape gets released
  739.                 activeFrame->DrawActiveBorder( ev );
  740.         }
  741.  
  742.     SOM_CATCH_ALL
  743.     SOM_ENDTRY
  744. }
  745.  
  746. SOM_Scope void  SOMLINK ODWindowStateSelectODWindow(ODWindowState *somSelf, Environment *ev,
  747.         ODWindow* window)
  748. {
  749.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  750.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateSelectODWindow");
  751.  
  752.     SOM_TRY
  753.  
  754.         _fWindowModule->SelectWindow( ev, window->GetPlatformWindow( ev ));
  755.  
  756.     SOM_CATCH_ALL
  757.     SOM_ENDTRY
  758. } // SelectODWindow
  759.  
  760.  
  761. SOM_Scope void  SOMLINK ODWindowStateDragODWindow(ODWindowState *somSelf, Environment *ev,
  762.         ODWindow* window,
  763.         Point* startPoint,
  764.         Rect* draggingBounds)
  765. {
  766.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  767.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateDragODWindow");
  768.  
  769.     SOM_TRY
  770.     
  771.         // Check for command-click on window title:
  772.         if( TrackWindowPathPopUp(ev,window,*startPoint) )
  773.             return;
  774.     
  775.         WindowPtr    windowToDrag = window->GetPlatformWindow(ev);
  776.         Rect        dragRect;
  777.         KeyMap        keyMap;
  778.         GrafPtr        savePort;
  779.         GrafPtr        windowManagerPort;
  780.         RgnHandle    dragRegion;
  781.         RgnHandle    windowContentRegion;
  782.         long        dragResult;
  783.         short        topLimit;
  784.         short        newHorizontalWindowPosition;
  785.         short        newVerticalWindowPosition;
  786.         short        horizontalOffset;
  787.         short        verticalOffset;
  788.         Boolean        commandKeyDown = kODFalse;
  789.         
  790.         // Set up the Window Manager port.
  791.         GetPort(&savePort);
  792.         GetWMgrPort(&windowManagerPort);
  793.         SetPort(windowManagerPort);
  794.         SetClip(GetGrayRgn());
  795.         
  796.         // Check to see if the command key is down.  If it is, don’t bring the window to the
  797.         // front after the move.
  798.         GetKeys(keyMap);
  799.         if (keyMap[1] & 0x8000)
  800.             commandKeyDown = kODTrue;
  801.     
  802.         if (WaitMouseUp())
  803.         {
  804.         
  805.             // Adjust the top of the dragging rectangle so that it’s below the menu bar
  806.             topLimit = LMGetMBarHeight() + 4;
  807.             dragRect = *draggingBounds;
  808.             if (dragRect.top < topLimit)
  809.                 dragRect.top = topLimit;
  810.         
  811.             if ((commandKeyDown != kODFalse) || (window->IsFloating(ev) == kODFalse)) 
  812.             {
  813.                 
  814.                 if (commandKeyDown == kODFalse)
  815.                     // If there are floating windows, clip the dragging outline to draw behind the floaters.
  816.                     ClipAbove(somSelf->GetFrontNonFloatingPlatformWindow(ev));
  817.                 else
  818.                     // If the command key was down, clip the outline to draw behind any windows above
  819.                     // the window being dragged.
  820.                     ClipAbove(windowToDrag);
  821.     
  822.             }
  823.                 
  824.             // Create a region to drag
  825.             dragRegion = ODNewRgn();
  826.             CopyRgn(GetStructureRegion(windowToDrag), dragRegion);
  827.             
  828.             // Drag the window around
  829.             dragResult = DragGrayRgn(dragRegion, *startPoint, &dragRect, &dragRect, noConstraint, nil);
  830.         
  831.             // Restore the port right now for coordinate conversion.
  832.             SetPort(savePort);
  833.     
  834.             if (dragResult != 0) 
  835.             {
  836.                 horizontalOffset = (ODSShort) (dragResult & 0xFFFF);
  837.                 verticalOffset = (ODSShort) (dragResult >> 16);
  838.         
  839.                 // Only move it if it stayed inside the dragging box.
  840.                 if (verticalOffset != -32768) 
  841.                 {
  842.                     windowContentRegion = GetContentRegion(windowToDrag);
  843.                     newHorizontalWindowPosition = (**windowContentRegion).rgnBBox.left + horizontalOffset;
  844.                     newVerticalWindowPosition = (**windowContentRegion).rgnBBox.top + verticalOffset;
  845.                     
  846.                     MoveWindow((WindowPtr) windowToDrag, newHorizontalWindowPosition, newVerticalWindowPosition, kODFalse);
  847.                     
  848.                 }
  849.             }
  850.         
  851.             // Get rid of the dragging region
  852.             DisposeRgn(dragRegion);
  853.         }
  854.  
  855.         // Restore the port
  856.         SetPort(savePort);
  857.  
  858.         // Bring the window forward if the command key wasn’t down
  859.         if (commandKeyDown == kODFalse)
  860.             somSelf->SelectODWindow(ev, window);
  861.     
  862.     SOM_CATCH_ALL
  863.     SOM_ENDTRY
  864. }
  865.  
  866. SOM_Scope void  SOMLINK ODWindowStateShowODWindow(ODWindowState *somSelf, Environment *ev,
  867.         ODWindow* window)
  868. {
  869.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  870.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateShowODWindow");
  871.  
  872.     SOM_TRY
  873.     
  874.         _fWindowModule->ShowWindow( ev, window->GetPlatformWindow( ev ),
  875.                 window->IsFloating( ev ) ? kODWinLayerFloating
  876.                                          : kODWinLayerDocument );
  877.  
  878.     SOM_CATCH_ALL
  879.     SOM_ENDTRY
  880. }
  881.  
  882.  
  883. SOM_Scope void  SOMLINK ODWindowStateHideODWindow(ODWindowState *somSelf, Environment *ev,
  884.         ODWindow* window)
  885. {
  886.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  887.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateHideODWindow");
  888.  
  889.     SOM_TRY
  890.  
  891.         _fWindowModule->HideWindow( ev, window->GetPlatformWindow( ev ));
  892.  
  893.     SOM_CATCH_ALL
  894.     SOM_ENDTRY
  895. }
  896.  
  897. /*
  898.  *  for ODWindowIterator
  899.  */
  900.  
  901. SOM_Scope ODULong  SOMLINK ODWindowStateAddIterator(ODWindowState *somSelf, Environment *ev,
  902.         ODWindowIterator* iterator)
  903. {
  904.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  905.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateAddIterator");
  906.  
  907.     LinkedListIterator* iter = kODNULL; ODVolatile(iter);
  908.  
  909.     SOM_TRY
  910.     
  911.         iter = new LinkedListIterator(_fWindowList);
  912.         _fIteratorCount++;
  913.             
  914.     SOM_CATCH_ALL
  915.     
  916.         ODDeleteObject(iter);
  917.         
  918.     SOM_ENDTRY
  919.  
  920.     return (ODULong) iter;
  921. }
  922.  
  923. SOM_Scope ODWindow*  SOMLINK ODWindowStateFirst(ODWindowState *somSelf, Environment *ev,
  924.         ODULong iteratorID)
  925. {
  926.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  927.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateFirst");
  928.  
  929.     ODWindow* window = kODNULL;
  930.  
  931.     SOM_TRY
  932.     
  933.         LinkedListIterator* iterator = (LinkedListIterator*) iteratorID; 
  934.         WindowLink* link = (WindowLink*) iterator->First();
  935.         
  936.         while (link && link->ShouldRemove())
  937.             link = (WindowLink*) iterator->Next();
  938.             
  939.         if (link)
  940.             window = link->fWindow;
  941.  
  942.     SOM_CATCH_ALL
  943.     SOM_ENDTRY
  944.     
  945.     return window;
  946. }
  947.  
  948. SOM_Scope ODWindow*  SOMLINK ODWindowStateNext(ODWindowState *somSelf, Environment *ev,
  949.         ODULong iteratorID)
  950. {
  951.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  952.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateNext");
  953.  
  954.     ODWindow* window = kODNULL;
  955.  
  956.     SOM_TRY
  957.     
  958.         LinkedListIterator* iterator = (LinkedListIterator*) iteratorID; 
  959.         WindowLink* link = (WindowLink*) iterator->Next();
  960.  
  961.         while (link && link->ShouldRemove())
  962.             link = (WindowLink*) iterator->Next();
  963.  
  964.         if (link)
  965.             window = link->fWindow;
  966.  
  967.     SOM_CATCH_ALL
  968.     SOM_ENDTRY
  969.     
  970.     return window;
  971. }
  972.  
  973. SOM_Scope ODWindow*  SOMLINK ODWindowStateLast(ODWindowState *somSelf, Environment *ev,
  974.         ODULong iteratorID)
  975. {
  976.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  977.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateLast");
  978.  
  979.     ODWindow* window = kODNULL;
  980.  
  981.     SOM_TRY
  982.     
  983.         LinkedListIterator* iterator = (LinkedListIterator*) iteratorID; 
  984.         WindowLink* link = (WindowLink*) iterator->Last();
  985.  
  986.         while (link && link->ShouldRemove())
  987.             link = (WindowLink*) iterator->Previous();
  988.  
  989.         if (link)
  990.             window = link->fWindow;
  991.  
  992.     SOM_CATCH_ALL
  993.     SOM_ENDTRY
  994.     
  995.     return window;
  996. }
  997.  
  998. SOM_Scope ODWindow*  SOMLINK ODWindowStatePrevious(ODWindowState *somSelf, Environment *ev,
  999.         ODULong iteratorID)
  1000. {
  1001.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1002.     ODWindowStateMethodDebug("ODWindowState","ODWindowStatePrevious");
  1003.  
  1004.     ODWindow* window = kODNULL;
  1005.  
  1006.     SOM_TRY
  1007.     
  1008.         LinkedListIterator* iterator = (LinkedListIterator*) iteratorID; 
  1009.         WindowLink* link = (WindowLink*) iterator->Previous();
  1010.  
  1011.         while (link && link->ShouldRemove())
  1012.             link = (WindowLink*) iterator->Previous();
  1013.  
  1014.         if (link)
  1015.             window = link->fWindow;
  1016.  
  1017.     SOM_CATCH_ALL
  1018.     SOM_ENDTRY
  1019.     
  1020.     return window;
  1021. }
  1022.  
  1023. SOM_Scope ODBoolean  SOMLINK ODWindowStateIsNotComplete(ODWindowState *somSelf, Environment *ev,
  1024.         ODULong iteratorID)
  1025. {
  1026.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1027.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateIsNotComplete");
  1028.     
  1029.     ODBoolean isNotComplete = kODFalse;
  1030.  
  1031.     SOM_TRY
  1032.  
  1033.         LinkedListIterator* iterator = (LinkedListIterator*) iteratorID; 
  1034.         isNotComplete = iterator->IsNotComplete();
  1035.     
  1036.     SOM_CATCH_ALL
  1037.     SOM_ENDTRY
  1038.  
  1039.     return isNotComplete;
  1040. }
  1041.  
  1042. SOM_Scope void  SOMLINK ODWindowStateRemoveIterator(ODWindowState *somSelf, Environment *ev,
  1043.         ODULong iteratorID)
  1044. {
  1045.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1046.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateRemoveIterator");
  1047.  
  1048.     SOM_TRY
  1049.     
  1050.         LinkedListIterator* iterator = (LinkedListIterator*) iteratorID; 
  1051.         ODDeleteObject(iterator);
  1052.         _fIteratorCount--;
  1053.         
  1054.         if (_fIteratorCount == 0) // Clear items marked for deletion during iteration
  1055.         {
  1056.             LinkedListIterator iter(_fWindowList);
  1057.             for ( WindowLink* link = (WindowLink*) iter.First();
  1058.                     iter.IsNotComplete(); 
  1059.                     link = (WindowLink*) iter.Next())
  1060.             {
  1061.                 if (link->ShouldRemove())
  1062.                 {
  1063.                     iter.RemoveCurrent();
  1064.                     delete link;
  1065.                 }
  1066.             }
  1067.         }
  1068.  
  1069.     SOM_CATCH_ALL
  1070.     SOM_ENDTRY
  1071. }
  1072.  
  1073.  
  1074. SOM_Scope void  SOMLINK ODWindowStateActivateWindow(ODWindowState *somSelf, Environment *ev,
  1075.         ODPlatformWindow platformWindow)
  1076. {
  1077.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1078.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateActivateWindow");
  1079.  
  1080.     SOM_TRY
  1081.     
  1082.         somSelf->HighlightAndActivateWindow(ev, platformWindow, kODTrue);
  1083.  
  1084.     SOM_CATCH_ALL
  1085.     SOM_ENDTRY
  1086. }
  1087.  
  1088. SOM_Scope void  SOMLINK ODWindowStateDeactivateWindow(ODWindowState *somSelf, Environment *ev,
  1089.         ODPlatformWindow platformWindow)
  1090. {
  1091.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1092.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateDeactivateWindow");
  1093.  
  1094.     SOM_TRY
  1095.  
  1096.         somSelf->HighlightAndActivateWindow(ev, platformWindow, kODFalse);
  1097.  
  1098.     SOM_CATCH_ALL
  1099.     SOM_ENDTRY
  1100. }
  1101.  
  1102. SOM_Scope void  SOMLINK ODWindowStateHighlightAndActivateWindow(ODWindowState *somSelf, Environment *ev,
  1103.         ODPlatformWindow platformWindow,
  1104.         ODBoolean activate)
  1105. {
  1106.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1107.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateHighlightAndActivateWindow");
  1108.  
  1109.     SOM_TRY
  1110.     
  1111.         // Send an activate event to the window.  Note that this
  1112.         // event has a flag bit set in the modifiers field to
  1113.         // tell ODWindow that this event was internally generated
  1114.         EventRecord event;
  1115.         SetActivateEvent(event, platformWindow, activate);
  1116.         _fSession->GetDispatcher(ev)->Dispatch(ev, &event);
  1117.  
  1118.     SOM_CATCH_ALL
  1119.     SOM_ENDTRY
  1120. }
  1121.  
  1122. SOM_Scope ODPlatformWindow  SOMLINK ODWindowStateGetLastFloatingPlatformWindow(ODWindowState *somSelf, Environment *ev)
  1123. {
  1124.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1125.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateGetLastFloatingPlatformWindow");
  1126.  
  1127.     WindowPtr    lastFloatingWindow = kODNULL;
  1128.  
  1129.     SOM_TRY
  1130.     
  1131.         WindowPtr    theWindow;
  1132.         ODWindow*    odWindow;
  1133.         
  1134.         theWindow = ::GetWindowList();
  1135.         lastFloatingWindow = kODNULL;
  1136.         
  1137.         // We have to search the entire window list because we don’t know what the windowKind
  1138.         // of other windows in the list might be, and we have account for the fact that a modal
  1139.         // dialog is up.
  1140.         
  1141.         // Note that this method is unaware of non-OD floating windows.  Thus, it ignores
  1142.         // windows that are not registered ODWindows.
  1143.  
  1144.         while (theWindow != kODNULL) 
  1145.         {
  1146.             if (somSelf->IsODWindow(ev,theWindow) != kODFalse) 
  1147.             {
  1148.                 odWindow = somSelf->AcquireODWindow(ev,theWindow);
  1149.                 if ( odWindow->IsFloating( ev ) && odWindow->IsShown( ev ))
  1150.                     lastFloatingWindow = theWindow;
  1151.                 ODReleaseObject(ev, odWindow);
  1152.             }
  1153.             theWindow = ::GetNextWindow(theWindow);
  1154.         }
  1155.         
  1156.     SOM_CATCH_ALL
  1157.     
  1158.         lastFloatingWindow = kODNULL;
  1159.         
  1160.     SOM_ENDTRY
  1161.  
  1162.     return lastFloatingWindow;
  1163. }
  1164.  
  1165. SOM_Scope ODPlatformWindow  SOMLINK ODWindowStateGetFrontNonFloatingPlatformWindow(ODWindowState *somSelf, Environment *ev)
  1166. {
  1167.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1168.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateGetFrontNonFloatingPlatformWindow");
  1169.  
  1170.     WindowPtr    firstNonFloater = ::FrontWindow();        ODVolatile( firstNonFloater );
  1171.     
  1172.     SOM_TRY
  1173.  
  1174.         WindowPtr lastFloater = somSelf->GetLastFloatingPlatformWindow( ev );
  1175.  
  1176.         if ( lastFloater != kODNULL )
  1177.             firstNonFloater = ::GetNextWindow( lastFloater );
  1178.  
  1179.         // Pass-over non-OD windows: we don't know if they are floating or not!
  1180.  
  1181.         while( !(( firstNonFloater == kODNULL ) 
  1182.                    || ( ::IsWindowVisible( firstNonFloater )
  1183.                            && somSelf->IsODWindow( ev, firstNonFloater ))))
  1184.         {
  1185.             firstNonFloater = ::GetNextWindow( firstNonFloater );
  1186.         }
  1187.  
  1188.     SOM_CATCH_ALL
  1189.  
  1190.         firstNonFloater = kODNULL;
  1191.  
  1192.     SOM_ENDTRY
  1193.  
  1194.     return firstNonFloater;
  1195.  
  1196. }
  1197.  
  1198. SOM_Scope void  SOMLINK ODWindowStatesomUninit(ODWindowState *somSelf)
  1199. {
  1200.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1201.     ODWindowStateMethodDebug("ODWindowState","ODWindowStatesomUninit");
  1202.  
  1203.     Environment* ev = somGetGlobalEnvironment();
  1204.  
  1205.     ODDeleteObject(_fWindowList);
  1206.     ODSafeReleaseObject(_fBaseMenuBar);        _fBaseMenuBar = kODNULL;
  1207.     ODSafeReleaseObject(_fCurrentMenuBar);    _fCurrentMenuBar = kODNULL;
  1208.     ODSafeReleaseObject( _fWindowModule );    _fWindowModule = kODNULL;
  1209. }
  1210.  
  1211. SOM_Scope ODSize  SOMLINK ODWindowStatePurge(ODWindowState *somSelf, Environment *ev,
  1212.         ODSize size)
  1213. {
  1214.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1215.     ODWindowStateMethodDebug("ODWindowState","ODWindowStatePurge");
  1216.  
  1217.     return 0;
  1218. }
  1219.  
  1220. SOM_Scope ODWindow*  SOMLINK ODWindowStateRegisterWindow(ODWindowState *somSelf, Environment *ev,
  1221.         ODPlatformWindow newWindow,
  1222.         ODType frameType,
  1223.         ODBoolean isRootWindow,
  1224.         ODBoolean isResizable,
  1225.         ODBoolean isFloating,
  1226.         ODBoolean shouldSave,
  1227.         ODBoolean shouldDispose,
  1228.         ODPart* rootPart,
  1229.         ODTypeToken viewType,
  1230.         ODTypeToken presentation,
  1231.         ODFrame* sourceFrame)
  1232. {
  1233.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1234.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateCreateWindow");
  1235.  
  1236.     ODWindow* window = kODNULL; ODVolatile(window);
  1237.  
  1238.     WASSERT_IS_PART_WRAPPER( ev, rootPart );
  1239.  
  1240.     SOM_TRY
  1241.         
  1242.         window = new ODWindow();
  1243.         if (window == kODNULL)
  1244.             THROW(kODErrCannotCreateWindow); // Note: Should we just use kODErrOutOfMemory?
  1245.             
  1246.         window->InitWindow(ev, newWindow, frameType,
  1247.                             isRootWindow, isResizable, isFloating, shouldSave, shouldDispose,
  1248.                             rootPart, viewType, presentation, sourceFrame);
  1249.         somSelf->AddWindow(ev,window);
  1250.         
  1251.     SOM_CATCH_ALL
  1252.     
  1253.         if (window)
  1254.         {
  1255.             TRY
  1256.                 window->CloseAndRemove(ev);
  1257.             CATCH_ALL
  1258.             ENDTRY
  1259.             window = kODNULL;
  1260.         }
  1261.                     
  1262.     SOM_ENDTRY
  1263.  
  1264.     return window;
  1265. }
  1266.  
  1267. SOM_Scope ODWindow*  SOMLINK ODWindowStateRegisterWindowForFrame(ODWindowState *somSelf, Environment *ev,
  1268.         ODPlatformWindow newWindow,
  1269.         ODFrame* frame,
  1270.         ODBoolean isRootWindow,
  1271.         ODBoolean isResizable,
  1272.         ODBoolean isFloating,
  1273.         ODBoolean shouldSave,
  1274.         ODBoolean shouldDispose,
  1275.         ODFrame* sourceFrame)
  1276. {
  1277.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1278.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateCreateWindow");
  1279.  
  1280.     ODWindow* window = kODNULL; ODVolatile(window);
  1281.  
  1282.     SOM_TRY
  1283.     
  1284.         window = new ODWindow();
  1285.         if (window == kODNULL)
  1286.             THROW(kODErrCannotCreateWindow); // Note: Should we just use kODErrOutOfMemory?
  1287.             
  1288.         window->InitWindowForFrame(ev, newWindow, frame,
  1289.                             isRootWindow, isResizable, isFloating, shouldSave,  shouldDispose, sourceFrame);
  1290.         somSelf->AddWindow(ev,window);
  1291.  
  1292.     SOM_CATCH_ALL
  1293.         
  1294.         if (window)
  1295.         {
  1296.             TRY
  1297.                 window->Close(ev);
  1298.             CATCH_ALL
  1299.             ENDTRY
  1300.             window = kODNULL;
  1301.         }
  1302.             
  1303.     SOM_ENDTRY
  1304.  
  1305.     return window;
  1306. }
  1307.  
  1308. SOM_Scope ODWindow*  SOMLINK ODWindowStateAcquireWindow(ODWindowState *somSelf, Environment *ev,
  1309.         ODID id)
  1310. {
  1311.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1312.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateAcquireWindow");
  1313.  
  1314.     ODWindow* window = kODNULL;
  1315.     
  1316.     SOM_TRY
  1317.     
  1318.             ODWindowIterator* iter = kODNULL; 
  1319.  
  1320.             iter = somSelf->CreateWindowIterator(ev);
  1321.         
  1322.             for (ODWindow* win = iter->First(ev); iter->IsNotComplete(ev);
  1323.                     win = iter->Next(ev))
  1324.             {
  1325.                 if (win->GetID(ev) == id)
  1326.                 {
  1327.                     window = win; 
  1328.                     break;
  1329.                 }
  1330.             }
  1331.             ODDeleteObject(iter);
  1332.  
  1333.             if (window)
  1334.                 window->Acquire(ev);
  1335.  
  1336.     SOM_CATCH_ALL
  1337.         
  1338.         window = kODNULL;
  1339.             
  1340.     SOM_ENDTRY
  1341.  
  1342.     return window;
  1343. }
  1344.  
  1345. SOM_Scope void  SOMLINK ODWindowStateInternalize(ODWindowState *somSelf, Environment *ev,
  1346.         ODDraft* draft)
  1347. {
  1348.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1349.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateInternalize");
  1350.     
  1351.     OrderedCollection* wsuIDCollection = kODNULL; ODVolatile(wsuIDCollection);
  1352.     
  1353.     SOM_TRY
  1354.     
  1355.         // To avoid calling Select in OpenWindows, we use this piece of cross-method state
  1356.         // A better solution might be to change ODOpenDraft to distinguish between the
  1357.         // opendraft and activateopendraft (from the dialog) cases. See also #1295739
  1358.         
  1359.         _fActivateOnOpen = (somSelf->GetRootWindowCount(ev, draft) > 0);
  1360.  
  1361.         ODULong offset, offsetLimit;
  1362.         ODStorageUnitRef suRef;
  1363.  
  1364. #if ODDebug
  1365.         // These variables get used further below for a sanity check
  1366.         ODUShort initialRootWindowCount;
  1367.         TempODPart rootPartOfDraft = ODAcquireRootPartOfDraft( ev, draft );    
  1368. #endif
  1369.  
  1370.         TempODStorageUnit draftProps = draft->AcquireDraftProperties(ev); // -- TÇ tempobj'd
  1371.         
  1372.         if (ODSUExistsThenFocus(ev, draftProps,kODPropRootFrameList, kODStrongStorageUnitRefs))
  1373.         {
  1374.             offsetLimit = draftProps->GetSize(ev);
  1375.     
  1376.             // Get collection of windowstorageunit ids belonging to the draft here.  We'll
  1377.             // use it below to ensure that we don't reopen open windows.
  1378.         
  1379.             wsuIDCollection = new OrderedCollection;
  1380.             WindowPtr theWindow = ::GetWindowList();    
  1381.             while (theWindow != kODNULL)
  1382.             {
  1383.                 if (somSelf->IsODWindow(ev,theWindow) != kODFalse)
  1384.                 {
  1385.                     TempODWindow odWindow = somSelf->AcquireODWindow(ev,theWindow);
  1386.                     if ( ODObjectsAreEqual(ev, odWindow->GetDraft(ev) , draft) )
  1387.                     {
  1388.                         ODStorageUnit* storageU = odWindow->GetRootFrame(ev)->GetStorageUnit(ev);
  1389.                         if ( storageU )
  1390.                             wsuIDCollection->AddLast( (ElementType)(storageU->GetID(ev)) );
  1391.                     }
  1392.                 }
  1393.                 theWindow = GetNextWindow(theWindow);
  1394.             }
  1395.         
  1396.             TempODStorageUnitView draftPropsView = draftProps->CreateView(ev);
  1397.             for (offset = 0; offset < offsetLimit; offset += sizeof(ODStorageUnitRef))
  1398.             {
  1399.                 draftPropsView->SetOffset(ev,offset);
  1400.                 StorageUnitViewGetValue(draftPropsView,ev,sizeof(ODStorageUnitRef), (ODValue)&suRef);
  1401.                 if (draftPropsView->IsValidStorageUnitRef(ev, suRef))
  1402.                 {
  1403.                     ODStorageUnitID wsuID = draftPropsView->GetIDFromStorageUnitRef(ev,suRef);
  1404.                     if ( !wsuIDCollection->Contains((ElementType)wsuID) )
  1405.                     {
  1406.                         ODFrame *rootFrame = draft->AcquireFrame(ev, wsuID);
  1407.                         if (rootFrame)
  1408.                         {
  1409.                             TRY{
  1410.                                 TempODPart rootPart = rootFrame->AcquirePart(ev);
  1411. #if ODDebug
  1412.                                 if ( ODObjectsAreEqual( ev, rootPart, rootPartOfDraft ))
  1413.                                     initialRootWindowCount = somSelf->GetRootWindowCount( ev, draft );
  1414. #endif
  1415.                                 rootPart->Open(ev, rootFrame);
  1416. #if ODDebug
  1417.                                 if ( ODObjectsAreEqual( ev, rootPart, rootPartOfDraft )
  1418.                                      && initialRootWindowCount == somSelf->GetRootWindowCount( ev, draft ))
  1419.                                 {
  1420.                                     WARN( "Root part of draft did not open a root window!  Check your isRootWindow flag." );
  1421.                                 }
  1422. #endif
  1423.                             }CATCH_ALL{
  1424.                                     TRY
  1425.                                         rootFrame->Close(ev);
  1426.                                     CATCH_ALL
  1427.                                     ENDTRY
  1428.                                 RERAISE;
  1429.                             }ENDTRY
  1430.                             rootFrame->Release(ev);
  1431.                         }
  1432.                     }
  1433.                 }
  1434.             }    
  1435.             ODDeleteObject(wsuIDCollection);
  1436.             
  1437.             somSelf->SetDefaultWindowTitles(ev,draft);
  1438.         }
  1439.  
  1440.     SOM_CATCH_ALL
  1441.     
  1442.         ODDeleteObject(wsuIDCollection);
  1443.         
  1444.     SOM_ENDTRY
  1445. }
  1446.  
  1447. SOM_Scope void  SOMLINK ODWindowStateExternalize(ODWindowState *somSelf, Environment *ev,
  1448.         ODDraft* draft)
  1449. {
  1450.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1451.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateExternalize");
  1452.  
  1453.     SOM_TRY
  1454.     
  1455.         somSelf->SetDefaultWindowTitles(ev,draft);
  1456.     
  1457.         ODULong offset, offsetLimit;
  1458.         ODFrame* rootFrame = kODNULL;
  1459.         
  1460.         TempODStorageUnit draftProps = draft->AcquireDraftProperties(ev);
  1461.         
  1462.         ODSUForceFocus(ev, draftProps, kODPropRootFrameList, kODStrongStorageUnitRefs);
  1463.         
  1464.         offset = 0;
  1465.         offsetLimit = draftProps->GetSize(ev);
  1466.     
  1467.         // Use the Window Manager list, since it's ordered
  1468.         // Note: we write the windows out back to front, since we create them in internalize
  1469.         // with the "behind" pointer -1. This only works because ShowODWindow does not bring
  1470.         // the newly shown window in front of the other invisible ones, as does ShowWindow.
  1471.  
  1472.         WindowListIterator iter;
  1473.         
  1474.         for (WindowPtr window = iter.Last(); iter.IsNotComplete(); window = iter.Previous())
  1475.         {
  1476.             if (somSelf->IsODWindow(ev,window))
  1477.             {
  1478.                 TempODWindow odWindow = somSelf->AcquireODWindow(ev,window); // DMc refcount - make temp
  1479.                 if (odWindow 
  1480.                     && (odWindow->ShouldSave(ev)) 
  1481.                     && (ODObjectsAreEqual(ev, odWindow->GetDraft(ev), draft)))
  1482.                 {
  1483.                     if (odWindow->GetStorageUnit(ev) == kODNULL) 
  1484.                     {
  1485.                         TempODStorageUnit    su = draft->CreateStorageUnit(ev);
  1486.                         odWindow->SetStorageUnit(ev, su);
  1487.                     }
  1488.                     odWindow->Externalize(ev);
  1489.     
  1490.                     rootFrame = odWindow->GetRootFrame(ev);
  1491.                     draftProps->SetOffset(ev,offset);    // $opt: Won't the offset be correct automatically? -TC
  1492.                     ODSetStrongSURefProp(ev, draftProps, kODNULL, kODNULL, rootFrame->GetStorageUnit(ev)->GetID(ev));
  1493.                     offset += sizeof(ODStorageUnitRef); // $opt: Won't the offset be correct automatically? -TC
  1494.                 }
  1495.             }
  1496.         }
  1497.         
  1498.         if (offset < offsetLimit)
  1499.             draftProps->DeleteValue(ev,offsetLimit - offset);
  1500.                     
  1501.     SOM_CATCH_ALL
  1502.     SOM_ENDTRY
  1503. }
  1504.  
  1505. SOM_Scope void  SOMLINK ODWindowStateSetDefaultWindowTitles(ODWindowState *somSelf, Environment *ev,
  1506.         ODDraft* draft)
  1507. {
  1508.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1509.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateSetDefaultWindowTitles");
  1510.  
  1511.     //!!! Needs work. Should add counter
  1512.     // Sets default window titles for all root windows of the given draft,
  1513.     // based on the file name.
  1514.  
  1515.     ODWindowIterator* iter = kODNULL; ODVolatile(iter);
  1516.     PlatformFile* file = kODNULL; ODVolatile(file);
  1517.         
  1518.     SOM_TRY
  1519.         
  1520.         ODContainer* container = draft->GetDocument(ev)->GetContainer(ev);
  1521.         
  1522.         file = GetPlatformFileFromContainer(ev, container);
  1523.  
  1524.         char    windowName[256];
  1525.     
  1526.         iter = somSelf->CreateWindowIterator(ev);
  1527.     
  1528.         for (ODWindow* window = iter->First(ev); iter->IsNotComplete(ev);
  1529.                 window = iter->Next(ev))
  1530.         {
  1531.             if ( (ODObjectsAreEqual(ev, window->GetDraft(ev), draft)) && window->IsRootWindow(ev) )
  1532.             {
  1533.                 file->GetAsciiName(windowName,235);
  1534.                 
  1535.                 ODULong draftNum = 0;
  1536.                 
  1537.                 TRY
  1538.                     draftNum = GetDraftNumFromDraft(ev, draft);
  1539.                 CATCH_ALL
  1540.                 ENDTRY
  1541.                 
  1542.                 if (draftNum != 0)
  1543.                 {
  1544.                     CToPascalString(windowName);
  1545.  
  1546.                     const ODSShort kMaxNumberSuffixLength = 10;                    
  1547.                     char theNum[kMaxNumberSuffixLength];
  1548.                     NumToString(draftNum, (StringPtr)theNum); // Macintosh Specific
  1549.  
  1550.                     ODSLong savedRefNum;
  1551.                     BeginUsingLibraryResources(savedRefNum);
  1552.                     ReplaceIntoString( kODDraftTextResID, (StringPtr)windowName,
  1553.                             (StringPtr)theNum, (StringPtr)windowName );
  1554.                     EndUsingLibraryResources(savedRefNum);
  1555.                     PascalToCString((StringPtr)windowName);
  1556.                 }
  1557.     
  1558.                 window->SetWindowTitle(ev, windowName);
  1559.             }
  1560.         }
  1561.         ODDeleteObject(iter);
  1562.         ODDeleteObject(file);
  1563.  
  1564.     SOM_CATCH_ALL
  1565.  
  1566.         ODDeleteObject(iter);
  1567.         ODDeleteObject(file);
  1568.  
  1569.     SOM_ENDTRY
  1570. }
  1571.  
  1572. SOM_Scope void  SOMLINK ODWindowStateOpenWindows(ODWindowState *somSelf, Environment *ev,
  1573.         ODDraft* draft)
  1574. {
  1575.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1576.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateOpenWindows");
  1577.  
  1578.     ODWindowIterator* iter = kODNULL; ODVolatile(iter);
  1579.  
  1580.     SOM_TRY
  1581.  
  1582.         if (draft)
  1583.         {
  1584.             iter = somSelf->CreateWindowIterator(ev);
  1585.         
  1586.             // Windows were externalize/internalized back to front
  1587.             for (ODWindow* window = iter->First(ev); iter->IsNotComplete(ev);
  1588.                     window = iter->Next(ev))
  1589.             {
  1590.                 if (ODObjectsAreEqual(ev, window->GetDraft(ev) , draft))
  1591.                 {
  1592.                     window->Open(ev); // A no-op if its already open
  1593.                     if (_fActivateOnOpen && window->IsShown(ev)) // The draft is already open
  1594.                         window->Select(ev);
  1595.                 }
  1596.             }
  1597.             ODDeleteObject(iter);
  1598.         }
  1599.         _fActivateOnOpen = kODFalse;
  1600.         
  1601.     SOM_CATCH_ALL
  1602.  
  1603.         _fActivateOnOpen = kODFalse;
  1604.         ODDeleteObject(iter);
  1605.  
  1606.     SOM_ENDTRY
  1607.     
  1608. }
  1609.  
  1610. SOM_Scope void  SOMLINK ODWindowStateCloseWindows(ODWindowState *somSelf, Environment *ev,
  1611.         ODDraft* draft)
  1612. {
  1613.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1614.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateCloseWindows");
  1615.  
  1616.     SOM_TRY
  1617.     
  1618.         ODWindowIterator* iter = somSelf->CreateWindowIterator(ev);
  1619.         
  1620.         for (ODWindow* window = iter->First(ev); iter->IsNotComplete(ev); window = iter->Next(ev))
  1621.         {
  1622.             if (ODObjectsAreEqual(ev, window->GetDraft(ev), draft ))
  1623.             {
  1624.                 window->Acquire(ev); // Close Releases
  1625.                 window->Close(ev);
  1626.             }
  1627.         }
  1628.         ODDeleteObject(iter);
  1629.  
  1630.     
  1631.     SOM_CATCH_ALL
  1632.     SOM_ENDTRY
  1633. }
  1634.  
  1635. SOM_Scope ODUShort  SOMLINK ODWindowStateGetWindowCount(ODWindowState *somSelf, Environment *ev)
  1636. {
  1637.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1638.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateGetWindowCount");
  1639.  
  1640.     ODUShort count = 0;
  1641.  
  1642.     SOM_TRY
  1643.     
  1644.         if (_fWindowList)
  1645.             count = _fWindowList->Count();
  1646.         
  1647.     SOM_CATCH_ALL
  1648.     SOM_ENDTRY
  1649.     
  1650.     return count;
  1651. }
  1652.  
  1653. SOM_Scope ODUShort  SOMLINK ODWindowStateGetRootWindowCount(ODWindowState *somSelf, Environment *ev,
  1654.         ODDraft* draft)
  1655. {
  1656.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1657.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateGetRootWindowCount");
  1658.  
  1659.     ODUShort count = 0;
  1660.     ODWindowIterator* iter = kODNULL; ODVolatile(iter);
  1661.     
  1662.     SOM_TRY
  1663.     
  1664.         if (draft)
  1665.         {
  1666.             iter = somSelf->CreateWindowIterator(ev);
  1667.         
  1668.             for (ODWindow* window = iter->First(ev); iter->IsNotComplete(ev);
  1669.                     window = iter->Next(ev))
  1670.             {
  1671.                 if (window->IsRootWindow(ev) && (ODObjectsAreEqual(ev, window->GetDraft(ev), draft)))
  1672.                 {
  1673.                     count++;
  1674.                 }
  1675.             }
  1676.             ODDeleteObject(iter);
  1677.         }
  1678.     
  1679.     SOM_CATCH_ALL
  1680.  
  1681.             ODDeleteObject(iter);
  1682.  
  1683.     SOM_ENDTRY
  1684.     
  1685.     return count;
  1686. }
  1687.  
  1688. SOM_Scope ODUShort  SOMLINK ODWindowStateGetTotalRootWindowCount(ODWindowState *somSelf, Environment *ev)
  1689. {
  1690.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1691.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateGetTotalRootWindowCount");
  1692.  
  1693.     //!!! Should get count directly from collection
  1694.     
  1695.     ODUShort count = 0;
  1696.     ODWindowIterator* iter = kODNULL; ODVolatile(iter);
  1697.     
  1698.     SOM_TRY
  1699.  
  1700.         iter = somSelf->CreateWindowIterator(ev);
  1701.     
  1702.         for (ODWindow* window = iter->First(ev); iter->IsNotComplete(ev);
  1703.                 window = iter->Next(ev))
  1704.         {
  1705.             if (window->IsRootWindow(ev))
  1706.                 count++;
  1707.         }
  1708.         ODDeleteObject(iter);
  1709.         
  1710.     SOM_CATCH_ALL
  1711.  
  1712.         ODDeleteObject(iter);
  1713.  
  1714.     SOM_ENDTRY
  1715.     
  1716.     return count;
  1717. }
  1718.  
  1719. SOM_Scope ODBoolean  SOMLINK ODWindowStateIsODWindow(ODWindowState *somSelf, Environment *ev,
  1720.         ODPlatformWindow aWindow)
  1721. {
  1722.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1723.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateIsODWindow");
  1724.  
  1725.     ODWindowIterator* iter = kODNULL; ODVolatile(iter);
  1726.     ODBoolean isODWindow = kODFalse;
  1727.         
  1728.     SOM_TRY
  1729.  
  1730.         iter = somSelf->CreateWindowIterator(ev);
  1731.     
  1732.         for (ODWindow* window = iter->First(ev); iter->IsNotComplete(ev);
  1733.                 window = iter->Next(ev))
  1734.         {
  1735.             if (window && (aWindow == window->GetPlatformWindow(ev)))
  1736.             {
  1737.                 isODWindow = kODTrue;
  1738.                 break;
  1739.             }
  1740.         }
  1741.         ODDeleteObject(iter);
  1742.  
  1743.     
  1744.     SOM_CATCH_ALL
  1745.  
  1746.         ODDeleteObject(iter);
  1747.  
  1748.     SOM_ENDTRY
  1749.     
  1750.     return isODWindow;
  1751. }
  1752.  
  1753. SOM_Scope ODWindow*  SOMLINK ODWindowStateAcquireODWindow(ODWindowState *somSelf, Environment *ev,
  1754.         ODPlatformWindow aWindow)
  1755. {
  1756.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1757.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateAcquireODWindow");
  1758.  
  1759.     ODWindowIterator* iter = kODNULL; ODVolatile(iter);
  1760.     ODWindow* odWindow = kODNULL;
  1761.         
  1762.     SOM_TRY
  1763.     
  1764.         iter = somSelf->CreateWindowIterator(ev);
  1765.     
  1766.         for (ODWindow* window = iter->First(ev); iter->IsNotComplete(ev);
  1767.                 window = iter->Next(ev))
  1768.         {
  1769.             if (window && (aWindow == window->GetPlatformWindow(ev)))
  1770.             {
  1771.                 odWindow = window;
  1772.                 break;
  1773.             }
  1774.         }
  1775.         ODDeleteObject(iter);
  1776.         
  1777.         if (odWindow)
  1778.             odWindow->Acquire(ev);
  1779.  
  1780.     SOM_CATCH_ALL
  1781.  
  1782.         ODDeleteObject(iter);
  1783.         odWindow = kODNULL;
  1784.  
  1785.     SOM_ENDTRY
  1786.     
  1787.     return odWindow;
  1788. }
  1789.  
  1790. SOM_Scope ODWindowIterator*  SOMLINK ODWindowStateCreateWindowIterator(ODWindowState *somSelf, Environment *ev)
  1791. {
  1792.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1793.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateCreateWindowIterator");
  1794.  
  1795.     ODWindowIterator* iter = kODNULL; ODVolatile(iter);
  1796.     
  1797.     SOM_TRY
  1798.  
  1799.         iter = new ODWindowIterator;
  1800.         THROW_IF_NULL(iter); // "new" does not throw for SOM objects
  1801.         iter->InitWindowIterator(ev, somSelf);
  1802.         
  1803.     SOM_CATCH_ALL
  1804.     
  1805.         ODDeleteObject(iter);
  1806.         
  1807.     SOM_ENDTRY
  1808.     
  1809.     return iter;
  1810. }
  1811.  
  1812. SOM_Scope ODWindow*  SOMLINK ODWindowStateAcquireActiveWindow(ODWindowState *somSelf, Environment *ev)
  1813. {
  1814.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1815.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateAcquireActiveWindow");
  1816.  
  1817.     ODWindow* odWindow = kODNULL;            ODVolatile( odWindow );
  1818.  
  1819.     SOM_TRY
  1820.  
  1821.         WindowPtr platformWindow = kODNULL;
  1822.  
  1823.         //    • First we need to find out the frontmost window
  1824.         platformWindow = somSelf->GetFrontNonFloatingPlatformWindow(ev);
  1825.         
  1826.         if (platformWindow)
  1827.         {
  1828.             // Check to see if the ODWindow is active.
  1829.             odWindow = somSelf->AcquireODWindow(ev,platformWindow);
  1830.             if ( odWindow == kODNULL || !odWindow->IsActive( ev ))
  1831.                 ODReleaseObject( ev, odWindow );    // Sets odWindow to NULL
  1832.         }
  1833.  
  1834.     SOM_CATCH_ALL
  1835.  
  1836.         ODReleaseObject( ev, odWindow );    // Sets odWindow to NULL
  1837.  
  1838.     SOM_ENDTRY
  1839.  
  1840.     return odWindow;
  1841. }
  1842.  
  1843. SOM_Scope void  SOMLINK ODWindowStateSetBaseMenuBar(ODWindowState *somSelf, Environment *ev,
  1844.         ODMenuBar* theMenuBar)
  1845. {
  1846.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1847.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateSetBaseMenuBar");
  1848.  
  1849.     SOM_TRY
  1850.         
  1851.         // $$$$$ Change this error code to be more explicit. -VL
  1852.         ASSERT(theMenuBar, kODErrIllegalNullInput);
  1853.     
  1854.         if (!ODObjectsAreEqual(ev, theMenuBar, _fBaseMenuBar))
  1855.         {
  1856.             ODULong generation;
  1857.             if (_fBaseMenuBar)
  1858.                 generation = _fBaseMenuBar->GetGeneration(ev) + 1;
  1859.             else
  1860.                 generation = 1;
  1861.             ODReleaseObject(ev, _fBaseMenuBar);
  1862.             theMenuBar->Acquire(ev);
  1863.             _fBaseMenuBar = theMenuBar;
  1864.             _fBaseMenuBar->SetGeneration(ev,generation);
  1865.         }
  1866.  
  1867.     SOM_CATCH_ALL
  1868.     SOM_ENDTRY
  1869. }
  1870.  
  1871. SOM_Scope ODMenuBar*  SOMLINK ODWindowStateCopyBaseMenuBar(ODWindowState *somSelf, Environment *ev)
  1872. {
  1873.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1874.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateCopyBaseMenuBar");
  1875.     
  1876.     ODMenuBar* menuBar = kODNULL;
  1877.     
  1878.     SOM_TRY
  1879.  
  1880.         if (_fBaseMenuBar)
  1881.             menuBar = _fBaseMenuBar->Copy(ev);
  1882.     
  1883.     SOM_CATCH_ALL
  1884.     SOM_ENDTRY
  1885.     
  1886.     return menuBar;    // -- TÇ: CopyBaseMenuBar is an 'acquire' function.
  1887. }
  1888.  
  1889. SOM_Scope void  SOMLINK ODWindowStateAdjustPartMenus(ODWindowState *somSelf, Environment *ev)
  1890. {
  1891.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1892.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateAdjustPartMenus");
  1893.  
  1894.     SOM_TRY
  1895.  
  1896.         TempODFrame targetFrame 
  1897.             = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev,_fMenuFocus);
  1898.             
  1899.         // To support root menu items like Print. 
  1900.         // Other platforms may choose to add a new focus for this
  1901.         
  1902.         ODFrame* rootFrame;
  1903.         { TempODWindow window = somSelf->AcquireActiveWindow(ev) ;    
  1904.           rootFrame = window ? window->GetRootFrame(ev) : kODNULL;
  1905.         }
  1906.         
  1907.         if (rootFrame)
  1908.         {
  1909.             TempODPart targetPart = rootFrame->AcquirePart(ev); // -- TÇ tempobj'd
  1910.             targetPart->AdjustMenus(ev,rootFrame);
  1911.         }    
  1912.             
  1913.         if (targetFrame && (targetFrame != rootFrame))
  1914.         {
  1915.             TempODPart targetPart = targetFrame->AcquirePart(ev); // -- TÇ tempobj'd
  1916.             targetPart->AdjustMenus(ev,targetFrame);
  1917.         }
  1918.         
  1919.     SOM_CATCH_ALL
  1920.     SOM_ENDTRY
  1921. }
  1922.  
  1923. SOM_Scope ODMenuBar*  SOMLINK ODWindowStateCreateMenuBar(ODWindowState *somSelf, Environment *ev,
  1924.         ODPlatformMenuBar menuBar)
  1925. {
  1926.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1927.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateCreateMenuBar");
  1928.  
  1929.     ODMenuBar* mb = kODNULL;  ODVolatile(mb);
  1930.  
  1931.     SOM_TRY
  1932.     
  1933.         mb = new ODMenuBar;
  1934.         THROW_IF_NULL(mb);    // "new" does not THROW for SOM objects
  1935.         mb->InitMenuBar(ev, _fSession, menuBar);
  1936.     
  1937.     SOM_CATCH_ALL
  1938.  
  1939.         ODDeleteObject(mb);
  1940.  
  1941.     SOM_ENDTRY
  1942.         
  1943.     return mb;
  1944. }
  1945.  
  1946. SOM_Scope ODCanvas*  SOMLINK ODWindowStateCreateCanvas(ODWindowState *somSelf, Environment *ev,
  1947.         ODGraphicsSystem graphicsSystem,
  1948.         ODPlatformCanvas platformCanvas,
  1949.         ODBoolean isDynamic,
  1950.         ODBoolean isOffscreen)
  1951. {
  1952.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1953.     ODWindowStateMethodDebug("ODWindowState","CreateCanvas");
  1954.  
  1955.     ODCanvas* canvas = kODNULL;  ODVolatile(canvas);
  1956.  
  1957.     SOM_TRY
  1958.  
  1959.         canvas = new ODCanvas;
  1960.         THROW_IF_NULL(canvas);    // "new" does not THROW for SOM objects
  1961.         canvas->InitCanvas(ev, graphicsSystem,platformCanvas,isDynamic,isOffscreen);
  1962.         
  1963.     SOM_CATCH_ALL
  1964.     
  1965.         ODDeleteObject(canvas);
  1966.         
  1967.     SOM_ENDTRY
  1968.     
  1969.     return canvas;
  1970. }
  1971.  
  1972. SOM_Scope ODFacet*  SOMLINK ODWindowStateCreateFacet(ODWindowState *somSelf, Environment *ev,
  1973.         ODFrame* frame,
  1974.         ODShape* clipShape,
  1975.         ODTransform* externalTransform,
  1976.         ODCanvas* canvas,
  1977.         ODCanvas* biasCanvas)
  1978. {
  1979.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  1980.     ODWindowStateMethodDebug("ODWindowState","CreateFacet");
  1981.  
  1982.     ODFacet* facet = kODNULL;  ODVolatile(facet);
  1983.     
  1984.     SOM_TRY
  1985.  
  1986.         facet = new ODFacet;
  1987.         THROW_IF_NULL(facet);    // "new" does not THROW for SOM objects
  1988.         facet->InitFacet(ev, frame, clipShape, externalTransform, canvas, biasCanvas);
  1989.     
  1990.     SOM_CATCH_ALL
  1991.     
  1992.         ODDeleteObject(facet);
  1993.         
  1994.     SOM_ENDTRY
  1995.     
  1996.     return facet;
  1997. }
  1998.  
  1999. SOM_Scope void    SOMLINK ODWindowStateRepairWindowOrder(ODWindowState *somSelf, Environment *ev)
  2000. {
  2001.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  2002.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateRepairWindowOrder");
  2003.  
  2004.     // This method is no longer in use as of OpenDoc 1.2
  2005.  
  2006. #ifdef OBSOLETE
  2007.  
  2008.     // ODWindowState calls this private method when it suspects that some alien code
  2009.     // (the toolbox or an INIT) has messed with the Window Manager window list behind
  2010.     // its back.  This method will force all non-floating ODWindows to be behind all
  2011.     // floating ODWindows.  Non-ODWindows are ignored.  
  2012.     //
  2013.     // BUG: If there are nested dialogs,
  2014.     // AND the inner dialog calls ActivateFrontWindows (which calls this method) upon
  2015.     // dismissal (which it should), AND the outer dialog (which is now the top window) is
  2016.     // an ODWindow, then this method will move the outer dialog to appear behind the floaters.
  2017.     // There is currently no way to tell that a non-floating window is actually a modal
  2018.     // dialog window.  It turns out that this behavior shouldn't be a problem: because the
  2019.     // outer dialog is an ODWindow, it's frame will take the selection focus, causing
  2020.     // all floaters owned by other frames to be hidden.  Thus, when the inner dialog is
  2021.     // dismissed, the outer dialog is forced behind the floaters, but they are hidden,
  2022.     // so the user can't tell that the layering is "wrong."  I actually tested this with
  2023.     // Cyberdog.  Lucky!
  2024.     //
  2025.     // ANOTHER BUG: This method assumes that the caller to ActivateFrontWindows is first
  2026.     // doing the DisposeDialog.  If DisposeDialog is called after ActivateFrontWindows,
  2027.     // we'll still get the same ordering problem.  Fortunately, this can be fixed by the
  2028.     // part developer.
  2029.     // -CSL  7/30/96
  2030.  
  2031.     ODWindowIterator* iter = kODNULL; ODVolatile(iter);
  2032.     WindowPtr bottomFloatingMacWin = kODNULL;
  2033.     
  2034.     SOM_TRY
  2035.         
  2036.         // 1. Find bottom floating ODWindow
  2037.  
  2038.         // Note: It would seem to make sense to traverse the Window Manager (WM) window list
  2039.         // and check each window to see if it's a floating ODWindow.  Doing this is
  2040.         // very expensive because calling AcquireODWindow creates an iterator every time.
  2041.         // Instead, we do it the other way around--iterate through the non-ordered ODWindow
  2042.         // list and for each floater, find it by inexpensively traversing the WM window list.
  2043.         // This routine should be lightweight.
  2044.         iter = somSelf->CreateWindowIterator( ev );
  2045.         for (ODWindow* currentODWin = iter->First( ev ); iter->IsNotComplete( ev );
  2046.                 currentODWin = iter->Next( ev ))
  2047.         {
  2048.             // If it's a floater, find it in the WM List
  2049.             if ( currentODWin->IsFloating( ev ))
  2050.             {
  2051.                 // Traverse WM list
  2052.                 WindowPtr targetMacWin = currentODWin->GetPlatformWindow( ev );
  2053.                 ODBoolean targetIsDeeper = kODFalse;
  2054.                 WindowPtr currentMacWin = GetWindowList();
  2055.                 while ( currentMacWin )
  2056.                 {
  2057.                     if ( currentMacWin == bottomFloatingMacWin )
  2058.                         targetIsDeeper = kODTrue;
  2059.                         
  2060.                     if ( currentMacWin == targetMacWin )    // Found it
  2061.                     {
  2062.                         if ( targetIsDeeper || bottomFloatingMacWin == kODNULL )
  2063.                             bottomFloatingMacWin = targetMacWin;
  2064.                         break;
  2065.                     }
  2066.                     currentMacWin = GetNextWindow( currentMacWin );
  2067.                     WASSERTM( currentMacWin, "Didn't find the ODWindow!" );
  2068.                 }
  2069.             }
  2070.         }
  2071.  
  2072.         // 2. For all non-floating ODWindows on top of the bottom floater call SendBehind,
  2073.         // but don't alter the relative order of the non-floaters.
  2074.         if ( bottomFloatingMacWin != kODNULL )
  2075.         {
  2076.             // In this case we must make the outside loop walk the Window Manager list because
  2077.             // we need to move misplaced windows back in the correct order.  The inside loop
  2078.             // is actually embedded in the call to AcquireODWindow.  In most cases, there will
  2079.             // only be one window that needs to be moved, so the expense here isn't bad.
  2080.             WindowPtr sendBehindMacWin = bottomFloatingMacWin;
  2081.             WindowPtr currentMacWin = GetWindowList();
  2082.             while ( currentMacWin != kODNULL && currentMacWin != bottomFloatingMacWin )
  2083.             {
  2084.                 TempODWindow currentODWin = somSelf->AcquireODWindow( ev, currentMacWin );
  2085.                 if ( currentODWin != kODNULL && !currentODWin->IsFloating( ev ))
  2086.                 {
  2087.                     WindowPtr nextMacWin = GetNextWindow( currentMacWin );
  2088.                     SendBehind( currentMacWin, sendBehindMacWin );
  2089.                     sendBehindMacWin = currentMacWin;
  2090.                     currentMacWin = nextMacWin;
  2091.                 }
  2092.                 else
  2093.                     currentMacWin = GetNextWindow( currentMacWin );
  2094.             }
  2095.         }
  2096.  
  2097.         ODDeleteObject( iter );
  2098.  
  2099.     SOM_CATCH_ALL
  2100.  
  2101.         if ( iter )
  2102.             ODDeleteObject( iter );
  2103.  
  2104.     SOM_ENDTRY
  2105. #endif // OBSOLETE
  2106. }
  2107.  
  2108.  
  2109. SOM_Scope void    SOMLINK ODWindowStateSetWindowModule(ODWindowState *somSelf, Environment *ev,
  2110.         ODWindowModule* windowModule)
  2111. {
  2112.     ODWindowStateData *somThis = ODWindowStateGetData(somSelf);
  2113.     ODWindowStateMethodDebug("ODWindowState","ODWindowStateSetWindowModule");
  2114.     
  2115.     SOM_TRY
  2116.  
  2117.         if ( _fWindowModuleHasBeenSet )
  2118.             THROW( kODErrWindowModuleAlreadySet );
  2119.         else
  2120.         {
  2121.             _fWindowModuleHasBeenSet = kODTrue;
  2122.             if ( windowModule != kODNULL )
  2123.             {
  2124.                 ODReleaseObject( ev, _fWindowModule );
  2125.                 windowModule->Acquire( ev );
  2126.                 _fWindowModule = windowModule;
  2127.             }
  2128.         }
  2129.     
  2130.     SOM_CATCH_ALL
  2131.     SOM_ENDTRY
  2132. }
  2133.